//
//  SwipeViewController.m
//  UITest
//
//  Created by wp w on 12-6-27.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SwipeViewController.h"

@implementation SwipeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor grayColor];
    
    UISwipeGestureRecognizer *recognizer; 
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)]; 
    [[self view] addGestureRecognizer:recognizer]; 
    [recognizer release]; 
    
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)]; 
    [[self view] addGestureRecognizer:recognizer]; 
    [recognizer release]; 
    
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)]; 
    [[self view] addGestureRecognizer:recognizer]; 
    [recognizer release]; 
    
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; 
    [[self view] addGestureRecognizer:recognizer]; 
    [recognizer release]; 
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

//http://o0o0o0o.iteye.com/blog/875333
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer { 
    if (recognizer.direction==UISwipeGestureRecognizerDirectionDown) { 
        NSLog(@"swipe down");
    }
    else if (recognizer.direction==UISwipeGestureRecognizerDirectionUp) {
        NSLog(@"swipe up");
    }
    else if (recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
        NSLog(@"swipe left");
    }
    else if (recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"swipe right");
    }
}

@end
